package com.yazi.mxz.common.client;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.yazi.mxz.common.entity.beans.GoodsPromote;
import com.yazi.mxz.common.entity.beans.GoodsPromoteId;
import com.yazi.mxz.common.entity.beans.StorePromote;

public class ActFactory {
	static {
		DefaultConfig config = new DefaultConfig();
		config.setServerPath(ActConfig.getInstance().getJobDomain());
		JobFactory.setConfig(config);
	}
	public static void actStorePromoteJob(final StorePromote storePromote) {
		JsonObject<StorePromote> jsonObject = new JsonObject<StorePromote>() {

			@Override
			public StorePromote getObject() {
				return storePromote;
			}

			@Override
			public FilterProvider getFilter() {
				final Set<String> promote = new HashSet<String>();
				promote.add("startTime");
				promote.add("endTime");

				return new SimpleFilterProvider().addFilter(StorePromote.class.getSimpleName(),
						SimpleBeanPropertyFilter.filterOutAllExcept(promote));
			}
		};
		
		JobFactory.actStorePromoteJob(jsonObject);
	}
	
	public static void actGoodsPromnoteJob(final GoodsPromote goodsPromote) {
		JsonObject<GoodsPromote> jsonObject = new JsonObject<GoodsPromote>() {

			@Override
			public GoodsPromote getObject() {
				return goodsPromote;
			}

			@Override
			public FilterProvider getFilter() {
				final Set<String> promote = new HashSet<String>();
				promote.add("id");
				promote.add("startTime");
				promote.add("endTime");
				final Set<String> promoteId = new HashSet<String>();
				promoteId.add("type");

				return new SimpleFilterProvider().addFilter(GoodsPromote.class.getSimpleName(),
						SimpleBeanPropertyFilter.filterOutAllExcept(promote)).addFilter(GoodsPromoteId.class.getSimpleName(),
								SimpleBeanPropertyFilter.filterOutAllExcept(promoteId));
			}
		};
		
		JobFactory.actGoodsPromoteJob(jsonObject);
	}
	
	public static void actOrderSuccessJob() {
		JobFactory.actOrderSuccessJob();
	}
	
	public static void actOrderReturnedJob() {
		JobFactory.actOrderReturnedJob();
	}
	
	public static void actStoreGoodsSyncJob(final Long goodsId, final Long sync) {
		JsonObject<Map<String, Object>> jsonObject = new JsonObject<Map<String, Object>>() {

			@Override
			public Map<String, Object> getObject() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("goodsId", goodsId);
				map.put("sync", sync);
				return map;
			}

			@Override
			public FilterProvider getFilter() {
				return null;
			}
		};
		
		JobFactory.actStoreGoodsSyncJob(jsonObject);
	}
	
	public static void actEmailJob() {
		JobFactory.actEmailJob();
	}
	
	public static void actSmsJob() {
		JobFactory.actSmsJob();
	}
}
